﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LTM_Extra;

namespace LTM_Main
{
    public partial class AuthorCreation : Form
    {
        ContentProvider contentProvider;

        public AuthorCreation(ContentProvider contentProvider)
        {
            InitializeComponent();
            this.contentProvider = contentProvider;
        }

        private void AuthorCreation_Load(object sender, EventArgs e)
        {
            try
            {
            Variable userId = new Variable
            {
                LableText = "User ID:",
                Required = true,
                VariableName =Constants.IdKey,
                VariableType = Constants.VariableType.String
            };

            var variables=contentProvider.GetAuthorVariables();
            variables.Insert(0,userId);

            Helper.InitTableLayoutPanel(tlpAuthor, variables);
                 }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {try
            {
           var properties= Helper.GetPropertiesFromTableLayout(tlpAuthor);
           contentProvider.AddAuthor(properties);
           Close();
             }
            catch (Exception ex)
            {

                MessageBox.Show(ex.ToString());
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
